/*
============================================================================
 Name        : pd_image.cpp
 Author      : Jian(raphyer@hotmail.com)
 Version     :
 Copyright   : GPL
 Description : pd_image.cpp - source file
============================================================================
*/

// INCLUDE FILES

#include "pd_image.h"
#include "PdDefine.h"
#include "PdImageDecoder.h"


pd_image* pd_img_create(const DD_UNICODE* img_file, dd_size size) 
{
    __DD_CHECK_PTR(img_file, DD_UNICODE, return NULL)  ;

    pd_image* img = NULL ;

    TRAPD(err, img = (pd_image*)CPdImageDecoder::NewL(__ToPtrC16(img_file), TSize(size.width, size.height));) ;

    if (err != KErrNone) {
        DD_LOG("pd_img_create create the %S error = %d", img_file, err) ;
        return NULL ;
    } ;

    return img ;
}

/*
pd_image* pd_img_create_by_data(void* img_data, dd_size size) 
{

}
*/

void pd_img_destroy(pd_image* img) 
{
    __DD_ASSERT_DEFENSE(img, return) ;

    CPdImageDecoder* decoder = (CPdImageDecoder*)img ;
    delete decoder ;
}

DD_BOOL pd_img_is_ready(pd_image* img) 
{
    __DD_ASSERT_DEFENSE(img, return DD_FALSE) ;

    CPdImageDecoder* decoder = (CPdImageDecoder*)img ;
    return decoder->IsReady() ;
}

dd_size pd_img_size(pd_image* img) 
{
    dd_size size = {0, 0};
    __DD_ASSERT_DEFENSE(img, return size) ;

    CPdImageDecoder* decoder = (CPdImageDecoder*)img ;
    size.width  = decoder->ImageSize().iWidth ;
    size.height = decoder->ImageSize().iHeight ;
    return size ;
}

/* End of File */
